﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
    xmlns:wvrm="http://ns.woodbase.dk/Movies.xsd"
>
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="ArrayOfMovie">
    <table>
      <tr>
        <th>Title</th>
        <th>Genres</th>
        <th>Runtime</th>
        <th>Actors</th>
        <th>Year</th>
      </tr>
      <xsl:apply-templates select="Movie">
        <xsl:sort order="ascending" select="@title"/>
        <xsl:sort order="descending" select="@production-year" />
        <xsl:sort order="ascending" select="@genre" />
      </xsl:apply-templates>
    </table>
  </xsl:template>

  <xsl:template match="Movie">
    <tr>
      <td style="width:175px;">
        <xsl:value-of select="@title"/>
      </td>
      <td style="width:120px;">
        <xsl:for-each select=".//wvrm:genres">
          <xsl:value-of select="@name"/>
          <br />
        </xsl:for-each>
      </td>
      <td style="width:60px;">
        <xsl:if test="@runtime!=-1">
          <xsl:value-of select="@runtime"/>
        </xsl:if>
      </td>
      <td style="width:120px;">
        <xsl:for-each select=".//wvrm:actors">
          <xsl:value-of select="@given-name"/>
          <xsl:text xml:space="preserve"> </xsl:text>
          <xsl:value-of select="@last-name"/>
          <br />
        </xsl:for-each>
      </td>
      <td style="width:60px;">
        <xsl:value-of select="@production-year"/>
      </td>
      <!-- Test written as fully qualified expression -->
      <xsl:if test="not(ancestor::node()/attribute::rented) or ancestor::node()/attribute::rented='false'">
        <td>
          <img style="cursor:move;" src="/Images/Movies.png" alt="Drag me!" title="Drag me!" height="24" />
        </td>
      </xsl:if>
    </tr>
  </xsl:template>
</xsl:stylesheet>
